from django.db import models


# Create your models here.
class Tag(models.Model):
    name = models.CharField(max_length=100)


class Category(models.Model):
    name = models.CharField(max_length=100)
    parent = models.IntegerField(default=-1)


class Post(models.Model):
    # 文章标题
    title = models.CharField(max_length=30)
    # 节选
    excerpt = models.CharField(max_length=200, null=True, blank=True)
    # 内容
    content = models.TextField(null=True, blank=True)
    # 发布日期
    pub_date = models.DateTimeField(null=True, blank=True)
    # 阅读时间
    read_time = models.IntegerField(default=0, null=True, blank=True)
    # 访问量
    pageview = models.IntegerField(default=0)
    # 文章状态 0：草稿，1：公开，2：加密
    status = models.IntegerField(default=0)
    # 标签
    tags = models.ManyToManyField(Tag, null=True, blank=True)
    # 是否置顶
    is_top = models.BooleanField(default=False)
    # 分类
    category = models.ForeignKey("Category", on_delete=models.SET_NULL, null=True, blank=True)

    class Meta:
        ordering = ('-is_top', '-pub_date')


class Configration(models.Model):
    category = models.CharField(max_length=100, null=True, blank=True)
    key = models.CharField(max_length=100, null=True, blank=True)
    value = models.CharField(max_length=500, null=True, blank=True)
